package com.xk.app_mine.mview

import android.annotation.SuppressLint
import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.graphics.Path
import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatImageView
import com.xk.app_mine.R

class ArcImageView(context: Context, attrs: AttributeSet?) :
    AppCompatImageView(context, attrs) {
    private var mArcHeight = 0
    var path =  Path();
    var paint =  Paint();
    init  {
        val typedArray = context.obtainStyledAttributes(attrs, R.styleable.ArcImageView);
        mArcHeight = typedArray.getDimensionPixelSize(R.styleable.ArcImageView_arcHeight, 0);
        typedArray.recycle();

    }

    override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec)

    }

    override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
        super.onLayout(changed, left, top, right, bottom)
        setArc()
    }

    fun setArc(){
        path =  Path();
        path.moveTo(0F, 0F);
        path.lineTo(0F, height.toFloat());
        path.quadTo((width / 2).toFloat(),
            (height - 2 * mArcHeight).toFloat(), width.toFloat(), height.toFloat()
        );
        path.lineTo(width.toFloat(), 0F);
        path.close();
        paint =  Paint();
        paint.setColor(Color.RED);
        paint.setTextSize(80F);
        paint.setStyle(Paint.Style.FILL);
    }






    override fun onDraw(canvas: Canvas?) {
        canvas?.clipPath(path);
        super.onDraw(canvas)
    }

}